package homework_05;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 练习题
 */
public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要求阶乘的数字：");
        int n = sc.nextInt();
        System.out.println(numN(n));

        System.out.println("请输入要判断的年份：");
        int year = sc.nextInt();
        if(yeear(year)){
            System.out.println(year + "是闰年");
        }else{
            System.out.println(year + "是平年");
        }

        num();

        int[] arr = {1,4,7,0,34,89,20};
        arrSort(arr);
    }

    /**
     *
     * @param n 求n的阶乘
     * @return
     */
    public static int numN(int n){
        int m = 1;
        for(int i=1;i<=n;i++){
            m *= i;
        }
        return m;
    }

    public static boolean yeear(int year){
        boolean flg = false;
        if((year%4==0&&year%100!=0) || (year%400==0)){
            flg = true;
            return flg;
        }
        return flg;
    }

    public static void num(){
        int n = 201;
        int i;
        while(true){
            for(i=2;i<n/2;i++) {
                if (n % i == 0) {
                    break;
                }
            }
            if(i>=n/2){
                System.out.println("大于200的最小质数为" + n);
                break;
            }
            n++;
        }
    }

    public static void arrSort(int[] arr){
        System.out.println("排序前数组" + Arrays.toString(arr));
        for(int i=1;i<arr.length;i++){
            for(int j=0;j<arr.length-1;j++){
                if(arr[j]>arr[j+1]){
                    int m = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = m;
                }
            }
        }
        System.out.println("排序后数组为");
        for(int k=0;k<arr.length;k++){
            System.out.println(arr[k]);
        }
    }
}
